// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
//初始化数据库        
 const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()  
 
  var opid=event._openid
  try {
    var userinfos = {};
   await db.collection('user').where({
     _openid: opid
    }).get().then(res => {
       userinfos = res.data[0]
       event=res.data[0]
      console.log(res.data[0])
      
    })  
    return {
      event,
      xm: userinfos['xm'],
      sushe: userinfos['sushe'],
      openid: wxContext.OPENID,
      appid: wxContext.APPID,
      unionid: wxContext.UNIONID,
    }

  }catch(e){
    console.log(e)
  }
  
 
  
 
}